Skip to content

Fix #11093, #12377 FP mismatchingContainerIterator#5911

Merged
chrchr-github merged 6 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_Fix11093
Feb 9, 2024
Merged

Fix #11093, #12377 FP mismatchingContainerIterator#5911
chrchr-github merged 6 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_Fix11093

Conversation

@chrchr-github
Copy link
Copy Markdown
Collaborator

…r to get reference to container

@chrchr-github chrchr-github changed the title Fix #11093 FP: mismatchingContainerIterator caused by ternary operato… Fix #11093, #12377 FP mismatchingContainerIterator Jan 23, 2024
Comment thread lib/checkstl.cpp
ValueFlow::Value val = getLifetimeIteratorValue(iterTok);
if (!val.tokvalue)
continue;
if (!val.isKnown() && Token::simpleMatch(val.tokvalue->astParent(), ":"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lifetime values are never known. Also, this will lead to FNs as well. I think it would be better to check that the set of lifetimes are the same when there are multiple lifetimes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the problem that there is only one value? Otherwise, getLifetimeIteratorValue() would return an empty value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yea, thats right, but it should be multiple values. I wonder why we are not getting both lifetime.

I assumed the error is that one variable has the lifetime v1 and the other has the lifetime v2. It should have both lifetimes.

Comment thread lib/checkstl.cpp Outdated
for (std::size_t i = 0; i < address1.size(); ++i)
for (std::size_t j = 0; j < address2.size(); ++j)
if (isSameExpression(true, false, address1[i], address2[j], library, false, false))
return true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure the reason for doing this, but it seems like it would be better to check if the entire set matches. This could be written as a nested std::any_of but it should probably be a nested std::all_of.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for #12377. We used to get stuck on pv, which actually has two values (get1 or get2).

Copy link
Copy Markdown
Collaborator

@danmar danmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.. feel free to merge if paul is happy..

@chrchr-github
Copy link
Copy Markdown
Collaborator Author

@pfultz2 I think we should merge this, even if the ValueFlow is still wrong. As it stands, this check produces mostly FPs in daca.

@chrchr-github chrchr-github merged commit 503c109 into cppcheck-opensource:main Feb 9, 2024
@chrchr-github chrchr-github deleted the chr_Fix11093 branch February 9, 2024 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants